package com.uchengwang.ui.self.banner.holder;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;

import com.uchengwang.functions.image.ImageManager;
import com.uchengwang.ui.utils.UCommonUtil;

/**
 * Created by Sai on 15/8/4.
 * 网络图片加载例子 convenientBanner顶部viewpager滚动页
 */
public class NetworkImageHolderView implements Holder<String> {
    private ImageView imageView;
    private boolean isNeed = false;//是否需要拼接地址 默认不需要拼接
    private int type;//1头像  2享说 3U城内容,社团纳新,社团/校吧内的贴子内的图片;
    public NetworkImageHolderView(boolean isNeed, int type){
        this.isNeed = isNeed;
        this.type = type;
    }
    @Override
    public View createView(Context context) {
        //你可以通过layout文件来创建，也可以像我一样用代码创建，不一定是Image，任何控件都可以进行翻页
        imageView = new ImageView(context);
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        return imageView;
    }

    @Override
    public void UpdateUI(Context context,int position, String data) {
        if (isNeed){//需要拼接地址
            data = UCommonUtil.getUtil().getOssImageUrl(type) + data;
        }
        ImageManager.getInstance().loadImage(context, imageView, data, ImageManager.ImageType.NARMOL);
    }
}
